import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {IndexSideBarService} from "./index-side-bar.service";
import {MatDrawer} from "@angular/material/sidenav";

@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.less']
})
export class IndexComponent implements OnInit {

  @ViewChild("drawer", {static: true})
  private drawer: MatDrawer;

  constructor(private indexSideBarService: IndexSideBarService) {
    indexSideBarService.sideBar$.subscribe(flag => {

      if (!this.drawer) {
        return
      }

      if (flag === IndexSideBarService.close_flag) {
        this.drawer.close();
      } else if (flag === IndexSideBarService.open_flag) {
        this.drawer.open();
      }
    })
  }

  ngOnInit() {
  }

}
